<template>
  <div class="container">
    <el-row>
      <el-col :span="12">
        <el-input
          v-model="SearchVal"
          placeholder="请输入"
          class="input"
          @keyup.enter="enterSearch"
        >
          <template #append>
            <el-button :icon="Search" @click="enterSearch"></el-button>
          </template>
        </el-input>
      </el-col>
      <el-col :span="12">
        <el-button type="primary" @click="oneAdd">add</el-button>
        <el-button type="danger" @click="oneDelet">add</el-button>
      </el-col>
    </el-row>
    <el-table :data="tableData" stripe style="width: 100%">
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column prop="date" label="Date" width="240" />
      <el-table-column prop="name" label="Name" width="150" />
      <el-table-column prop="order" label="Order" width="150" />
      <el-table-column prop="address" label="Address" />
      <el-table-column prop="Operations">
        <template #default="scope">
          <el-button
            size="small"
            type="info"
            @click="handleEdit(scope.$index, scope.row)"
            >Edit</el-button
          >
          <el-button
            size="small"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
            >Delete</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <el-pagination
      background
      layout="prev, pager, next"
      :total="total"
      @current-change="currentChange"
    />
    <addvue
      :isShow="isShow"
      :info="info"
      @clonse="clones"
      @success="success"
    ></addvue>
  </div>
</template>
<script setup lang="ts">
import { ref } from "vue";
import { Search } from "@element-plus/icons-vue";
import addvue from "@/comments/add.vue";
import User from "../class/User";
import { ElMessage } from "element-plus";
import UserDto from "@/class/UserDto";
import { getList } from "@/http/index";
const SearchVal = ref("");
const total = ref(100);
const enterSearch = () => {};
const oneAdd = () => {
  isShow.value = true;
};
let userDto = ref<UserDto>(new UserDto());
const load = async () => {
  await getList(userDto.value);
};
const oneDelet = () => {};
const isShow = ref(false);
const info = ref<User>(new User());

const handleEdit = (index: number, row: User) => {
  console.log(index, row);
  info.value = row;
  isShow.value = true;
};
const handleDelete = (index: number, row: User) => {};
const currentChange = (val: number) => {
  console.log(val);
};
const clones = () => {
  isShow.value = false;
  info.value = new User();
};
const success = (message: string) => {
  console.log(message);

  isShow.value = false;
  info.value = new User();
  ElMessage.success(message);
};
const tableData = [
  {
    date: "2016-05-03",
    name: "Tom",
    order: 1,
    address: "No. 189, Grove St, Los Angeles",
  },
  {
    date: "2016-05-02",
    name: "Tom",
    order: 1,
    address: "No. 189, Grove St, Los Angeles",
  },
  {
    date: "2016-05-04",
    name: "Tom",
    order: 1,
    address: "No. 189, Grove St, Los Angeles",
  },
  {
    date: "2016-05-01",
    name: "Tom",
    order: 1,
    address: "No. 189, Grove St, Los Angeles",
  },
];
</script>
<style scoped lang="less">
.container {
  margin: 100px auto;
  width: 100%;
  .title {
    margin: 10px 0;
  }
  .input {
    width: 380px;
    margin-right: 20px;
  }
}
</style>
